/**************************************************************************************

 *  COSC603Project1 - Task 4: Java Re-engineering of Stutter.c
 *  Copyright (C) 2012 Jamie Xu

 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.

 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.

 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.

 *************************************************************************************/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

// TODO: Auto-generated Javadoc
/**
 * The Class COSC603Project1.
 */
public class COSC603Project1 {	
	
	/** The token list. Stores an ArrayList of all the "tokens" after the file is parsed. */
	static ArrayList<String> tokenList;
	
	/** The previous. Stores the previous token that was looked at. */
	static String previous;
	
	/** The current. Stores the current token that is now now being looked at. */
	static String current;
	
	/** The first flag. Since the first word in the file will not have a previous token. We need a flag to prevent errors. */
	static int firstFlag = 1;
	
	/**
	 * The main method. Since this program is quite simple in its task and implementation. Everything is in the main method.
	 *
	 * @param args the arguments
	 * @throws FileNotFoundException the file not found exception
	 */
	public static void main(String[] args) throws FileNotFoundException {
		// Initialize the list of tokens
		tokenList = new ArrayList<String>();
		
		// Open the file provided in the command line
		Scanner sc = new Scanner(new File(args[0]));
		
		// Omit these characters in the scan
		sc.useDelimiter("[({ \\r\\n,.!-+=;:?&})]+");
		
		// Loop while there are valid tokens
		while(sc.hasNext()) {
			// If not first token being read
			if(firstFlag == 0) {
				previous = current;

				current = sc.next();

				// Stutter detection - the current token is the same as the previous
				if (current.equals(previous)) {
					System.out.println(previous + " " + current);
				}
			}
			
			// If first token being read
			else if(firstFlag == 1) {
				current = sc.next();
				
				firstFlag = 0;
			}
		}
	}
}